<%@page contentType="text/html" pageEncoding="UTF-8" %>
<%@page import="com.trabalho1.model.ModelUsuario" %>
<%@page import="com.trabalho1.db.dao.DaoUsuario" %>
<%
// Controle de Sessao
Integer usuarioId = (Integer) session.getAttribute("id_usuario");

if (usuarioId == null)
{
    response.sendRedirect("index.jsp");
}
// Controle de Sessao
%>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Usuários</title>
        <link rel='stylesheet' type='text/css' href='css/style.css'  media='screen' />
        <script type='text/javascript' src='js/jquery/jquery-1.7.2.min.js'></script>
        <script type='text/javascript' src='js/jquery/plugins/validate/jquery.validate.min.js'></script>
        <script type='text/javascript' src='js/jquery/plugins/validate/additional-methods.min.js'></script>
        <script type='text/javascript' src='js/global.js'></script>
        <script type='text/javascript' src='js/usuario.js'></script>
    </head>
    <body>
        <div class="header">
            <div class="header-title">
                <h1>Usuários</h1>
            </div>
            <div class="header-menu">
                <a href="admin.jsp" title="Administração"><img src="image/menuHome.png" alt="" /></a>
                <a href="usuario_lista.jsp" title="Usuários"><img src="image/menuUser.png" alt="" /></a>
                <a href="telefone_lista.jsp" title="Telefones"><img src="image/menuPhone.png" alt="" /></a>
                <a href="endereco_lista.jsp" title="Endereços"><img src="image/menuAddress.png" alt="" /></a>
                <a href="logout.jsp" title="Sair"><img src="image/menuLogout.png" alt="" /></a>
            </div>
        </div>

        <input id="btnNew" type="button" value="Novo Usuário" /><br /><br />
        
        <table class="list">
            <thead>                
                <tr>
                    <th>Código</th>
                    <th>Nome</th>
                    <th>Email</th>
                    <th>Senha</th>
                    <th>Ação</th>
                </tr>
            </thead>
            <tbody>
            <%
            DaoUsuario daoUsuario = new DaoUsuario();        

            try
            {            
                Integer count = daoUsuario.findAll().size();
                
                if (count > 0)
                {
                    for (ModelUsuario mdlUsuario : daoUsuario.findAll()) {               
                        %>
                        <tr>
                            <td class="codigo"><%=mdlUsuario.getId_usuario()%></td>
                            <td><%=mdlUsuario.getNome()%></td>
                            <td><%=mdlUsuario.getEmail()%></td>
                            <td><%=mdlUsuario.getSenha()%></td>                        
                            <td class="acao">
                                <img class="edit"   rel="<%=mdlUsuario.getId_usuario()%>" src="image/iconEdit.png"   title="Editar"  />
                                <img class="delete" rel="<%=mdlUsuario.getId_usuario()%>" src="image/iconDelete.png" title="Excluir" />
                            </td>                        
                        </tr>
                        <%
                    }
                }
                else
                {
                    %>
                    <tr>
                        <td colspan="5">Nenhum registro cadastrado!</td>
                    </tr>
                    <% 
                }
            }
            catch(Exception e)
            {
                out.print("Erro ao listar usuários: " +e.getMessage());   
            }
            %>
        </table>            
    </body>
</html>